package cn.dnui_jzy913.dnuifood_16110100913.Fragment;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.List;

import cn.dnui_jzy913.dnuifood_16110100913.Adapter.OrderAdapter;
import cn.dnui_jzy913.dnuifood_16110100913.R;
import cn.dnui_jzy913.dnuifood_16110100913.bean.CommentsBean;
import cn.dnui_jzy913.dnuifood_16110100913.listener.RetrofitListener;
import cn.dnui_jzy913.dnuifood_16110100913.model.UserModel;

public class Fragment3 extends BaseFragment implements RetrofitListener<List<CommentsBean>> {
    private OrderAdapter adapter;
    private RecyclerView recyclerView;
    private UserModel userModel;

    @Override
    protected int initlayout() {
        return R.layout.fragment3;
    }

    @Override
    void initViews() {
        recyclerView = view.findViewById(R.id.f3_rv);
    }

    @Override
    void initEvents() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(
                getActivity(),
                LinearLayoutManager.VERTICAL,
                false
        );//布局效果---垂直布局
        recyclerView.setLayoutManager(linearLayoutManager);//设置效果
        recyclerView.setItemAnimator(new DefaultItemAnimator());//设置动画效果
    }

    @Override
    void initData() {
        userModel = new UserModel();
        userModel.getAllOrdersByUser(getUser_id(),this);
    }

    @Override
    public void onSuccess(List<CommentsBean> object, int flag) {
        adapter = new OrderAdapter(getActivity(),object,R.layout.dindan_item);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFalure() {
        showToast("网络错误11");
    }
}
